import django_filters
from django.shortcuts import render
from django_filters.rest_framework import DjangoFilterBackend
from rest_framework import viewsets, status
from rest_framework.filters import SearchFilter
from rest_framework.pagination import PageNumberPagination
from rest_framework.response import Response
from rest_framework.views import APIView

from apps.wool import models,ser


# Create your views here.


class page(PageNumberPagination):
    page_size = 10
    page_size_query_param = 'size'
    page_query_param = 'page'
class WooFilter(django_filters.FilterSet):
    id=django_filters.CharFilter(field_name='id',lookup_expr='icontains')
    wool_name=django_filters.CharFilter(field_name='wool_name',lookup_expr='icontains')
    class Meta:
        model = models.wool
        fields = ['wool_name', 'did_id']


class W1ViewSet(viewsets.ModelViewSet):
    queryset = models.w1.objects.all()
    serializer_class = ser.w1Ser

class WooViewSet(viewsets.ModelViewSet):
    queryset = models.wool.objects.all()
    serializer_class = ser.WoolSer
    filterset_class = WooFilter
    pagination_class = page
    filter_backends = (DjangoFilterBackend,SearchFilter)




